﻿using System;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using Microsoft.Reporting.WinForms;

namespace Labthink.PCSoft.UniversalHost4
{
    /// <summary>
    /// FrmLogPrint.xaml 的交互逻辑
    /// </summary>
    public partial class FrmLogPrint 
    {
        public DataSet DsData { get; set; }

        public FrmLogPrint()
        {
            InitializeComponent();
            var rd = Resources.MergedDictionaries.SingleOrDefault(r => r.Source != null && r.Source.OriginalString.Contains("default.xaml"));
            if (rd != null) Resources.MergedDictionaries.Remove(rd);
        }

       

        private void FrmLogPrint_OnLoaded(object sender, RoutedEventArgs e)
        {
          

            ReportViewer.LocalReport.ReportPath = AppDomain.CurrentDomain.BaseDirectory + "OperationLog.rdlc";
            ReportViewer.Messages = new ReportLanguage();
            ReportViewer.LocalReport.EnableExternalImages = true;
            ReportViewer.LocalReport.DataSources.Clear();

            foreach (DataTable dt in DsData.Tables)
            {
                ReportViewer.LocalReport.DataSources.Add(new ReportDataSource(dt.TableName, dt));
            }

            ReportViewer.RefreshReport();
        }

        private void ReportViewer_OnRenderingBegin(object sender, CancelEventArgs e)
        {
            foreach (RenderingExtension extension in ReportViewer.LocalReport.ListRenderingExtensions())
            {
                if (extension.Name == "WORDOPENXML" )
                {
                    //extension.Visible = false; // Property is readonly...
                    FieldInfo fi = extension.GetType().GetField("m_isVisible", BindingFlags.Instance | BindingFlags.NonPublic);
                    if (fi != null) fi.SetValue(extension, false);
                }
                if (extension.Name == "EXCELOPENXML" )
                {
                    //extension.Visible = false; // Property is readonly...
                    FieldInfo fi = extension.GetType().GetField("m_isVisible", BindingFlags.Instance | BindingFlags.NonPublic);
                    if (fi != null) fi.SetValue(extension, false);
                }
            }
        }

        private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
        {
            Close();
        }
    }
}
